<template>
  <!-- 充值流水 -->
  <view class="finance-logs-container">
    <List ref="list" :fetch-data="fetchData" :page-size="20">
      <mz-list>
        <FinanceLogItem v-for="(item) in list" :key="item.id" :data="item"></FinanceLogItem>
      </mz-list>
    </List>
  </view>
</template>

<script>
import { mapActions } from "vuex";
import List from "../../components/public/List/index.vue";
import FinanceLogItem from "./components/FinanceLogItem.vue";
export default {
  components: {
    List,
    FinanceLogItem
  },
  data() {
    return {
      searchParams: {},
      list: []
    };
  },
  onLoad(query) {
    console.log("query", query);

    this.searchParams = query;
    if (query.type == 1) {
      console.log("会员充值记录");

      uni.setNavigationBarTitle({
        title: "会员充值记录"
      });
    }
    if (query.type == 2) {
      console.log("会员消费记录");
      uni.setNavigationBarTitle({
        title: "会员消费记录"
      });
    }

    if (!this.$isNull(query.userid)) {
      console.log("充值消费记录");
      uni.setNavigationBarTitle({
        title: "充值消费记录"
      });
    }
  },
  onReady(){
    if (this.searchParams.type == 2) {
      console.log("会员消费记录");
      uni.setNavigationBarTitle({
        title: "会员消费记录"
      });
    }
  },
  methods: {
    ...mapActions({
      getMembersFinanceLog: "getMembersFinanceLog"
    }),
    async fetchData(params, refreshing) {
      let Search = {};
      for (let key in this.searchParams) {
        if (this.searchParams[key] || this.searchParams[key] === 0)
          Search[key] = this.searchParams[key];
      }
      let query = Object.assign({}, params, Search);
      try {
        let res = await this.getMembersFinanceLog(query);
        if (refreshing) this.list = [];
        this.list = this.list.concat(res.rows);
        return res;
      } catch (error) {
        return Promise.reject();
      }
    }
  }
};
</script>

<style lang="scss">
.finance-logs-container {
  height: 100%;
}
</style>
